package whr.common.utils;

public class ResponseApi<T> {


    private int code;
    private String msg;
    private T data;


    /**
     * 响应成功
     * @return
     */
    public static<T> ResponseApi success(){
        ResponseApi responseApi=new ResponseApi(ResEnum.success.getCode(), ResEnum.success.getMsg());
        responseApi.setData(null);
        return responseApi;
    }


    /**
     * 响应成功
     * @param t
     * @param <T>
     * @return
     */
    public static<T> ResponseApi success(T t){
        ResponseApi responseApi=new ResponseApi(ResEnum.success.getCode(), ResEnum.success.getMsg());
        responseApi.setData(t);
        return responseApi;
    }

    /**
     * 响应失败
     * @param
     * @param <T>
     * @return
     */
    public static<T> ResponseApi failed(){
        ResponseApi responseApi=new ResponseApi(ResEnum.failed.getCode(), ResEnum.failed.getMsg());
        responseApi.setData(null);
        return responseApi;
    }



    /**
     * 响应失败
     * @param t
     * @param <T>
     * @return
     */
    public static<T> ResponseApi failed(T t){
        ResponseApi responseApi=new ResponseApi(ResEnum.failed.getCode(), ResEnum.failed.getMsg());
        responseApi.setData(t);
        return responseApi;
    }




    public ResponseApi(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }


    public ResponseApi() {
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
